<template>
  <div class="container">
    <detail-bar />
    <div class="video-content">
      <div class="player-box">
        <my-player :src="url" />
      </div>
      <div class="player-num">
        <h4>{{ name }}</h4>
        <ul>
          <li
            :class="activeIndex == index ? 'active-video' : ''"
            v-for="(item, index) in videoList"
            :key="item.id"
            @click="changeVideo(item.url, index)"
          >
            {{ item.title }}
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import DetailBar from "../../components/detailbar/index";
import MyPlayer from "../../components/myPlayer/index";
import videoApi from "@/api/videos";
export default {
  name: "videoDetail",
  components: {
    DetailBar,
    MyPlayer,
  },
  data() {
    return {
      typeId: null,
      activeIndex: 0,
      url: "",
      name: "",
      videoList: [],
    };
  },
  created() {
    this.typeId = this.$route.query.id;
    if (this.typeId) {
      this.getData();
    }
  },
  methods: {
    getData() {
      videoApi
        .getDetail(this.typeId)
        .then(({ data: res }) => {
          console.log(res);
          this.name = res.data.name;
          this.videoList = res.data.data;
          if(this.videoList && this.videoList.length >0 ){
            this.url = this.videoList[0].url
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    changeVideo(url, index) {
      this.activeIndex = index;
      this.url = url
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  background: #f5f6f7;
}
.video-content {
  box-sizing: border-box;
  padding: 15px 50px;
  width: 100%;
  height: calc(100vh - 70px);
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  .player-box {
    width: 80%;
    height: 99%;
    background: #fff;
  }
  .player-num::-webkit-scrollbar {
    width: 0;
  }
  .player-num {
    overflow-y: auto;
    box-sizing: border-box;
    padding: 20px 5px;
    width: 15%;
    height: 99%;
    background: rgb(244, 244, 244);
    box-shadow: 0 0 20px #ccc;
    text-align: center;
    h4 {
      color: rgb(27, 46, 82);
    }
    ul {
      margin-top: 10px;
      li {
        cursor: pointer;
        padding: 3px 0;
        box-sizing: border-box;
      }
    }
  }
}
.active-video {
  border-radius: 2px;
  background: #fff;
  color: cornflowerblue;
}
</style>